#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    long long minimumTime(vector<int>& time, int totalTrips) {
        long long left = 1, right = 1e14 + 10;
        int n = time.size();
        while (left <= right)
        {
            long long allTrips = 0;
            long long mid = left + (right - left) / 2;
            for (int i = 0; i < n; i++)
            {
                allTrips += mid / time[i];
            }
            if (allTrips >= totalTrips)
            {
                right = mid - 1;
            }
            else if (allTrips < totalTrips)
            {
                left = mid + 1;
            }
        }
        return left;
    }
};